<?php
session_start();
?>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <?php include "jquery.php"; ?>

    </head>
    <body>

        <?php
        // the conference id from the previous page
        if (isset($_GET['conference_id'])) {

            $confid = intval($_GET['conference_id']);
            @mysql_connect('localhost', 'root', '') or die(mysql_error());
            mysql_select_db("mydb") or die(mysql_error());
            $get_name = mysql_query("Select long_name From conference Where conference_id = '$confid'") or die(mysql_error());
            $Get_name = mysql_fetch_assoc($get_name);
            echo "<h1>{$Get_name['long_name']}</h1>";
            echo "<h2>Invite Organizers </h2>";
        }
        // an array of alphabets
        $alphabets = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'
            , 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
        for ($i = 0; $i <= 25; $i++) { // loop on the 25 letters in the array
            $Letter = $alphabets[$i]; //save each letter in a variable 
            // make the letters links and when clicked it should send an ajax request to this page passing it the clicked letter   
            echo '<a href="#" onclick="javascript:AjaxRequest(this);">' . $Letter . '</a>&nbsp;';
        }
        // save the conference id in a variable 
        $confid = $_GET['conference_id'];
        // put the conference id in hidden input to get it in the javascript code in this page 
        echo '<input type="hidden" name="conference_id" id="conference_id" value="' . $confid . '"/> ';
        // }
        ?> 

        </br>
        </br>
        <div id="mydiv">

        </div>

    </body>
</html>
<head>
    <script language="javascript">
        // when a link letter is clicked, this code sends to inviteOrganizers page that 
        //loads in this page's div element the conference id and the clicked letter
        $(document).ready(function()
        {
            conferenceID = $("#conference_id").val();
            $.ajax({
                type:"POST",
                url: "inviteOrganizers.php",
                data:{
                    letter:"A",
                    conference_id:conferenceID
                },
                success: function(response)
                {
                    document.getElementById("mydiv").innerHTML = response;
                }
            });
                
            $("a").bind("click", function()
            {
                clicked_letter=$(this).html();
                    
                $.ajax({
                    type:"POST",
                    url: "inviteOrganizers.php",
                    data:{
                        letter:clicked_letter,
                        conference_id:conferenceID
                    },
                    success: function(response)
                    {
                        document.getElementById("mydiv").innerHTML = response;
                    }
                });
            });
                
        });
			
        // function that enables the dropdown list of every checked box,
        // it takes the check box itself and the number of the check box in the list which is also the number of the dropdown list  in the list
        function enable(e, i)             {
            // if the check box is checked
            if(e.checked==true) 
            {
                // get the id of the dropbox that corrosponds this check box and enable it
                document.getElementById("Committees"+i).disabled=false; 
            }
            // if the check box is unchecked
            if(e.checked==false) 
            {
                // get the id of the dropbox that corrosponds this check box and disable it
                document.getElementById("Committees"+i).disabled=true; 
            }
        }
        //When the Done button in inviteOrganizers is clicked it calls this method
        //This method gets all the checked checkboxes and the values of their linked drop down lists and put them in 2 arrays and sent them back to
        //inviteOrganizerspage
        function InvitationDone()
        {
            members=[];
            values=[];
            conferenceID = $("#conference_id").val();
            $("input[type=checkbox]:checked").each(function()
            {
                member=$(this).val();
                value=$("select[class="+$(this).val()+"]").val();
                members[members.length]=member;
                values[values.length]=value;
            });
            $.ajax({
                type:"POST",
                url:"inviteOrganizers.php",
                data:{
                    member_ids:members,
                    committees:values,
                    conference_id:conferenceID
                },
                success:function(response)
                {
                    $("#mydiv").fadeOut(300,function()
                    {
                        $("#mydiv").html(response);
                        $("#mydiv").fadeIn(300);
                    });
                }
            }
        );
        }
    </script>
</head>
